package guiWindows;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.Point;
import java.awt.ScrollPane;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.EventObject;
import java.util.LinkedList;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.AbstractCellEditor;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreeNode;

import mediator.ConstantsModel;
import objectsDiagram.Fluent;
import objectsDiagram.GatePanel;
import objectsDiagram.State;
import objectsDiagram.Task;

public class MainWindow extends JFrame {

	private static final long serialVersionUID = 1L;
    private ScrollPane jScrollPane;
    private Container content;
    private GUIDiagram guiDiagram;
    private JPanel propertiesPanel = null;
    private JMenuBar mainBar;
    private JMenu fileMenu;
    private JMenuItem itemOpenFile;
    private GatePanel joinPanel;
    private GatePanel splitPanel;
    private JTabbedPane tabs;
    private JTabbedPane diagramPanel = null;
    private JPanel fluentPanel;
    private JMenuItem itemNewFluent;
    private JTree tree;
    private DefaultTreeModel modelo;
    private DefaultMutableTreeNode top;  //  @jve:decl-index=0:
    private int indexForFluentId;
    private JPanel cursorPanel;
    private JButton sellectionButton;
    private JButton offFluentButton;
    private JButton onFluentButton;
    private JButton eraserButton;
    private Fluent currentFluent;  //  @jve:decl-index=0:
    private LinkedList<Fluent> listFluents;  //  @jve:decl-index=0:
    private JMenuItem itemSelectTemplates;
    private JMenu editionMenu;
    private JSplitPane splitFluentDiagram = null;  //  @jve:decl-index=0:visual-constraint="549,687"
    private JSplitPane splitSouthPanel = null;  //  @jve:decl-index=0:visual-constraint="642,740"
    private JList<String> listProperties = null;
    private JPanel propertyPanel = null;  //  @jve:decl-index=0:visual-constraint="419,51"
    private JScrollPane scrollPropertyPanel = null;  //  @jve:decl-index=0:visual-constraint="665,51"
    private DefaultListModel<String> modeloLista;
    private JMenuItem itemSaveProperty;
    private JMenuItem itemOpenProperty;
    private JMenu processMenu;
    private JMenuItem itemYawl2Fsp;
    private Vector<Task> vectorTask;
    private GUICreateProperties guiCreateProperties;
    private JMenuItem itemDeleteNewFluent;
    private JPopupMenu fluentPopup;
	private LinkedList<GUIDiagram> listGUIDiagrams;
	private Object[] traceStateList;

    public MainWindow(GUICreateProperties guiCreateProperties) {
    	this.guiCreateProperties = guiCreateProperties;
        initialize();
    }

    private void initialize() {
        this.setJMenuBar(getMainMenu());
        this.setLayout(new BorderLayout());
        this.setTitle("Fluent Logic Workflow Analyzer");
                
        joinPanel = new GatePanel();
        joinPanel.getOrButton().setEnabled(false);
        joinPanel.getAndButton().setEnabled(false);
        joinPanel.getXorButton().setEnabled(false);
        joinPanel.getNoneButton().setEnabled(false);
        splitPanel = new GatePanel();
        splitPanel.getOrButton().setEnabled(false);
        splitPanel.getAndButton().setEnabled(false);
        splitPanel.getXorButton().setEnabled(false);
        splitPanel.getNoneButton().setEnabled(false);
        tabs = new JTabbedPane();
        content = this.getContentPane();
        content.add(getSplitSouthPanel(), BorderLayout.CENTER);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(1000, 640);
        this.onFluentButton.setEnabled(false);
        this.offFluentButton.setEnabled(false);
        this.eraserButton.setEnabled(false);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        indexForFluentId = 0;
    }

    public JPanel getPropertiesPanel() {
        if (propertiesPanel == null) {
            propertiesPanel = new JPanel();
            propertiesPanel.setLayout(new BoxLayout(getPropertiesPanel(), BoxLayout.Y_AXIS));
            propertiesPanel.add(getFluentPanel());
            propertiesPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            tabs.add("SPLIT", splitPanel);
            tabs.add("JOIN", joinPanel);
            tabs.setPreferredSize(new Dimension(200, 150));
            tabs.setMaximumSize(new Dimension(200, 150));
            tabs.setMinimumSize(new Dimension(200, 150));
            propertiesPanel.add(tabs);
        }
        return propertiesPanel;
    }

    public JPanel getFluentPanel() {
        if (fluentPanel == null) {
            top = new DefaultMutableTreeNode("fluents");
            modelo = new DefaultTreeModel(top);
            tree = new JTree(modelo);
            
            DefaultTreeCellRenderer renderer =  (DefaultTreeCellRenderer) tree.getCellRenderer();  
            TreeCellEditor editor = new LeafCellEditor(tree, renderer,new LeafEditor());  
            tree.setCellEditor(editor);  
            tree.setEditable(true);

            tree.setRootVisible(false);
            tree.setDragEnabled(true);
            JScrollPane scrollPane = new JScrollPane(tree);

            fluentPanel = new JPanel();
            fluentPanel.setMinimumSize(new Dimension(200, 150));
            fluentPanel.setPreferredSize(new Dimension(200, 150));
            fluentPanel.add(scrollPane);
            fluentPanel.add(getCursorPanel());
            fluentPanel.setLayout(new BoxLayout(getFluentPanel(), BoxLayout.Y_AXIS));
            fluentPanel.setBorder(BorderFactory.createTitledBorder(null, "Fluents", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
            scrollPane.setPreferredSize(fluentPanel.getSize());
            scrollPane.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));

        }
        return fluentPanel;
    }

    private JPanel getCursorPanel() {
        if (cursorPanel == null) {
            cursorPanel = new JPanel();
            cursorPanel.setLayout(new FlowLayout());
            cursorPanel.setPreferredSize(new Dimension(200, 50));
            cursorPanel.setMaximumSize(new Dimension(200, 50));
            cursorPanel.setMinimumSize(new Dimension(200, 50));
            cursorPanel.add(getButtonCursorSellection());
            cursorPanel.add(getButtonCursorOnFluent());
            cursorPanel.add(getButtonCursorOffFluent());
            cursorPanel.add(getButtonCursorEraser());
        }
        return cursorPanel;
    }

    public JPanel getPropertyPanel() {
        if (propertyPanel == null) {
            propertyPanel = new JPanel();
            propertyPanel.setLayout(new BorderLayout());
            propertyPanel.setMinimumSize(new Dimension(200, 250));
            propertyPanel.setPreferredSize(new Dimension(200, 250));
            propertyPanel.add(guiCreateProperties, BorderLayout.CENTER);
        }
        return propertyPanel;
    }

    private JScrollPane getScrollpropertyPanel() {
        if (scrollPropertyPanel == null) {
            scrollPropertyPanel = new JScrollPane();
            scrollPropertyPanel.setSize(new Dimension(91, 68));
            scrollPropertyPanel.setBorder(BorderFactory.createTitledBorder(null, "Propertys", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
            scrollPropertyPanel.setViewportView(getPropertyPanel());
        }
        return scrollPropertyPanel;
    }

    public JButton getButtonCursorSellection() {
        if (sellectionButton == null) {
            sellectionButton = new JButton();
            sellectionButton.setPreferredSize(new Dimension(30, 30));
            sellectionButton.setIcon(new ImageIcon(getClass().getResource(ConstantsModel.ICON_CURSOR_SELECTION)));
        }
        return sellectionButton;
    }

    public JButton getButtonCursorOffFluent() {
        if (offFluentButton == null) {
            offFluentButton = new JButton();
            offFluentButton.setPreferredSize(new Dimension(30, 30));
            offFluentButton.setIcon(new ImageIcon(getClass().getResource(ConstantsModel.ICON_CURSOR_SELECTION_OFF)));
        }
        return offFluentButton;
    }

    public JButton getButtonCursorOnFluent() {
        if (onFluentButton == null) {
            onFluentButton = new JButton();
            onFluentButton.setPreferredSize(new Dimension(30, 30));
            onFluentButton.setIcon(new ImageIcon(getClass().getResource(ConstantsModel.ICON_CURSOR_SELECTION_ON)));
        }
        return onFluentButton;
    }

    public JButton getButtonCursorEraser() {
        if (eraserButton == null) {
            eraserButton = new JButton();
            eraserButton.setPreferredSize(new Dimension(30, 30));
            eraserButton.setIcon(new ImageIcon(getClass().getResource(ConstantsModel.ICON_CURSOR_ERASER)));
        }
        return eraserButton;
    }

    public JTabbedPane getDiagramPanel() {
        if (diagramPanel == null) {
            diagramPanel = new JTabbedPane();
        }
        return diagramPanel;
    }

    public void setListenerButtons(ActionListener al) {
        this.itemOpenFile.addActionListener(al);
        this.itemNewFluent.addActionListener(al);
        this.itemDeleteNewFluent.addActionListener(al);
        this.itemSaveProperty.addActionListener(al);
        this.itemOpenProperty.addActionListener(al);
        this.itemSelectTemplates.addActionListener(al);
        this.itemYawl2Fsp.addActionListener(al);
        this.onFluentButton.addActionListener(al);
        this.offFluentButton.addActionListener(al);
        this.sellectionButton.addActionListener(al);
        this.eraserButton.addActionListener(al);
    }

    public void setTreeSellectionListener(TreeSelectionListener tsl) {
        this.tree.addTreeSelectionListener(tsl);
    }

    private JMenuBar getMainMenu() {
        if (mainBar == null) {
            mainBar = new JMenuBar();
            mainBar.setBackground(new Color(170, 170, 170));
            mainBar.add(getMenuFile());
            mainBar.add(getEditionFile());
            mainBar.add(getProcess());
            mainBar.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return mainBar;
    }

    private JMenu getMenuFile() {
        if (fileMenu == null) {
            fileMenu = new JMenu("File");
            fileMenu.add(getItemOpenFile());
            fileMenu.add(getItemNewFluent());
            fileMenu.add(getItemDeleteFluent());
            fileMenu.add(getItemOpenProperty());
            fileMenu.add(getItemSaveProperty());
            fileMenu.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return fileMenu;
    }

    private JMenu getEditionFile() {
        if (editionMenu == null) {
            editionMenu = new JMenu("Edition");
            editionMenu.add(getItemSelectTempletes());
            editionMenu.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return editionMenu;
    }

    private JMenu getProcess() {
        if (processMenu == null) {
            processMenu = new JMenu("Process");
            processMenu.add(getItemYawl2Fsp());
            processMenu.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return processMenu;
    }

    public JMenuItem getItemOpenFile() {
        if (itemOpenFile == null) {
            itemOpenFile = new JMenuItem("Open File");
            itemOpenFile.setMnemonic('o');
            itemOpenFile.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return itemOpenFile;
    }

    public JMenuItem getItemNewFluent() {
        if (itemNewFluent == null) {
            itemNewFluent = new JMenuItem("New Fluent");
            itemNewFluent.setMnemonic('f');
            itemNewFluent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return itemNewFluent;
    }


    public JMenuItem getItemDeleteFluent() {
        if (itemDeleteNewFluent == null) {
            itemDeleteNewFluent = new JMenuItem("Delete Fluent");
            itemDeleteNewFluent.setMnemonic('d');
            itemDeleteNewFluent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return itemDeleteNewFluent;
    }

    public JMenuItem getItemOpenProperty() {
        if (itemOpenProperty == null) {
            itemOpenProperty = new JMenuItem("Open Property");
            itemOpenProperty.setMnemonic('a');
            itemOpenProperty.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return itemOpenProperty;
    }

    public JMenuItem getItemSaveProperty() {
        if (itemSaveProperty == null) {
            itemSaveProperty = new JMenuItem("Save Property");
            itemSaveProperty.setMnemonic('s');
            itemSaveProperty.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return itemSaveProperty;
    }

    public JMenuItem getItemSelectTempletes() {
        if (itemSelectTemplates == null) {
            itemSelectTemplates = new JMenuItem("Select Templates");
            itemSelectTemplates.setMnemonic('t');
            itemSelectTemplates.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return itemSelectTemplates;
    }


    public JMenuItem getItemYawl2Fsp() {
        if (itemYawl2Fsp == null) {
            itemYawl2Fsp = new JMenuItem("Call Yawl2Fsp");
            itemYawl2Fsp.setMnemonic('y');
            itemYawl2Fsp.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
        return itemYawl2Fsp;
    }

    public GatePanel getJoinPanel() {
        return joinPanel;
    }

    public GatePanel getSplitPanel() {
        return splitPanel;
    }

    public JTree getTree() {
        return tree;
    }

    public void loadDiagram(GUIDiagram newGUIDiagram) {
        guiDiagram = newGUIDiagram;
        jScrollPane = new ScrollPane();
        jScrollPane.add(guiDiagram);
        diagramPanel.add(guiDiagram.getId(), jScrollPane);
        diagramPanel.setMinimumSize(new Dimension(500,400));
        content.add(getSplitSouthPanel(), BorderLayout.CENTER);
    }

    public void clearDiagram() {
        diagramPanel.removeAll();
    }

    public void clearProperties(){
        guiCreateProperties.clearProperties();
    }

    public void clearFluents(){
        if(modelo.getChildCount(top)>0){
            tree.clearSelection();
            int countFluent = modelo.getChildCount(top);
            for(int i = 0;i<countFluent;i++){
                modelo.removeNodeFromParent((MutableTreeNode) modelo.getChild(top, 0));
            }
        }
        indexForFluentId=0;
        this.getButtonCursorOnFluent().setEnabled(false);
        this.getButtonCursorOffFluent().setEnabled(false);
        this.getButtonCursorEraser().setEnabled(false);
        this.getItemDeleteFluent().setEnabled(false);
    }

    public void addNewFluent(Fluent fluent) {
        currentFluent = fluent;		
        currentFluent.setId(((char)(65+indexForFluentId++))+"");
        DefaultMutableTreeNode newFluent = new DefaultMutableTreeNode("fluent :" + currentFluent.getId());
        DefaultMutableTreeNode listOn = new DefaultMutableTreeNode(ConstantsModel.TURN_ON_FLUENT);
        DefaultMutableTreeNode listOff = new DefaultMutableTreeNode(ConstantsModel.TURN_OFF_FLUENT);
        modelo.insertNodeInto(newFluent, top, modelo.getChildCount(top));
        modelo.insertNodeInto(listOn, newFluent, 0);
        modelo.insertNodeInto(listOff, newFluent, 1);
        tree.setRootVisible(true);
        tree.expandRow(0);
        tree.setRootVisible(false);
        tree.setSelectionRow(modelo.getChildCount(top)-1);
        this.setVisible(true);
    }
    
    public void setIndexForFluentId(int index){
    	this.indexForFluentId = index;
    }

    public void setCurrentFluent(Fluent fluent) {
        currentFluent = fluent;
    }

    public void setOffMouse() {
        try {
            Toolkit t = Toolkit.getDefaultToolkit();
            Cursor cursor = t.createCustomCursor(t.createImage(getClass().getResource(ConstantsModel.OFF_CURSOR)), new Point(0,0), ConstantsModel.OFF_CURSOR_TYPE);
            this.setCursor(cursor);
            cursor = this.getCursor();
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (HeadlessException e) {
            e.printStackTrace();
        }
    }

    public void setOnMouse() {
        try {
            Toolkit t = Toolkit.getDefaultToolkit();
            Cursor cursor = t.createCustomCursor(t.createImage(getClass().getResource(ConstantsModel.ON_CURSOR)), new Point(0, 0), ConstantsModel.ON_CURSOR_TYPE);
            this.setCursor(cursor);
            cursor = this.getCursor();
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (HeadlessException e) {
            e.printStackTrace();
        }
    }

    public void setSellectionMouse() {
        try {
            Toolkit t = Toolkit.getDefaultToolkit();
            Cursor cursor = t.createCustomCursor(t.createImage(getClass().getResource(ConstantsModel.NORMAL_CURSOR)), new Point(0, 0), ConstantsModel.NORMAL_CURSOR_TYPE);
            this.setCursor(cursor);
            cursor = this.getCursor();
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (HeadlessException e) {
            e.printStackTrace();
        }
    }

    public void setEraserMouse() {
        try {
            Toolkit t = Toolkit.getDefaultToolkit();
            t.getBestCursorSize(10, 10);
            Cursor cursor = t.createCustomCursor(t.createImage(getClass().getResource(ConstantsModel.ERASER_CURSOR)), new Point(0, 0), ConstantsModel.ERASER_CURSOR_TYPE);
            this.setCursor(cursor);
            cursor = this.getCursor();
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (HeadlessException e) {
            e.printStackTrace();
        }
    }

    public void setListFluent(LinkedList<Fluent> newListFluents) {
        this.listFluents = newListFluents;
        this.guiCreateProperties.setListFluent(newListFluents);
    }

    public LinkedList<Fluent> getListFluents() {
        return this.listFluents;
    }

    public DefaultTreeModel getModelo() {
        return modelo;
    }

    public void setModelo(DefaultTreeModel modelo) {
        this.modelo = modelo;
    }

    public DefaultListModel<String> getListModel(){
        if(modeloLista==null){
            modeloLista = new DefaultListModel<String>();
        }
        return modeloLista;
    }

    private JSplitPane getSplitFluentDiagram() {
        if (splitFluentDiagram == null) {
            splitFluentDiagram = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,getPropertiesPanel(),getDiagramPanel());
        }
        return splitFluentDiagram;
    }

    private JSplitPane getSplitSouthPanel() {
        if (splitSouthPanel == null) {
            splitSouthPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, getSplitFluentDiagram(),getPropertyPanel());
        }
        return splitSouthPanel;
    }

    public GUICreateProperties getGuiCreateProperties(){
        return guiCreateProperties;
    }

    public Fluent getSelectedFluent() {
        return currentFluent;
    }

    public void deleteFluent(){
        DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode)this.getTree().getLastSelectedPathComponent();
        modelo.removeNodeFromParent(mainNode);

        tree.setRootVisible(true);
        tree.expandRow(0);
        tree.setRootVisible(false);
        if(modelo.getChildCount(top) > 0){
            tree.setSelectionRow(modelo.getChildCount(top)-1);
        }
        this.setVisible(true);
    }

    private String getNameFluentTree(){
        DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode)this.getTree().getLastSelectedPathComponent();
        String idFluent="";
        if(mainNode != null){
            String nameNode = (String)mainNode.getUserObject();
            idFluent = nameNode.substring(nameNode.indexOf(":")+1, nameNode.length());
        }
        return idFluent;
    }
    
    private void setNameModified(String oldName){
        DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode)this.getTree().getLastSelectedPathComponent();
        if(mainNode != null){
            String nameNode = (String)mainNode.getUserObject();
            String idFluentModified = (String)mainNode.getUserObject();
            if(idFluentModified.contains(":")){
                idFluentModified = nameNode.substring(nameNode.indexOf(":")+1, nameNode.length());
            }
            for(Fluent fluent : listFluents){
                if(fluent.getId().equals(oldName)){
                    if(isCorrectName(idFluentModified)){
                       fluent.setId(idFluentModified.toUpperCase());
                    }else{
                        mainNode = (DefaultMutableTreeNode)this.getTree().getLastSelectedPathComponent();
                        mainNode.setUserObject("fluent :"+oldName);
                        JOptionPane.showMessageDialog(this, "Incorrect name for fluent");
                    }
                    break;
                }
            }
        }
    }
    
    private boolean isCorrectName(String newName){
        System.out.println(newName);
        Pattern pat = Pattern.compile("^[A-Z]([A-Za-z0-9_])*");
        Matcher mat = pat.matcher(newName);
        if (mat.matches()) {
            System.out.println(mat.find());
            return true;
        }        
        return false;
    }
    

    class LeafCellEditor extends DefaultTreeCellEditor {  
        public LeafCellEditor(JTree tree, DefaultTreeCellRenderer renderer) {  
            super(tree, renderer);  
        }  

        public LeafCellEditor(JTree tree, DefaultTreeCellRenderer renderer,  
                TreeCellEditor editor) {  
            super(tree, renderer, editor);  
        }  
    }  

    @SuppressWarnings("serial")
	class LeafEditor extends AbstractCellEditor implements TreeCellEditor,  
    ActionListener {  
        JTextField textField;  

        public LeafEditor() {  
            textField = new JTextField();  
            textField.addActionListener(this);  
        }  

        public Component getTreeCellEditorComponent(JTree tree, Object value,boolean isSelected,boolean expanded,boolean leaf, int row) {  
            DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
            textField.setText(node.toString());  
            return textField;  
        }  

        public boolean isCellEditable(EventObject event) {  
            //System.out.println("event = " + event);  
            // Get initial setting  
            boolean returnValue = super.isCellEditable(event);  
            if(event instanceof MouseEvent) {  
                // If still possible, check if current tree node is a leaf  
                if (returnValue) {  
                    JTree tree = (JTree)event.getSource();  
                    Object node = tree.getLastSelectedPathComponent();  
                    if ((node != null) && (node instanceof TreeNode)) {  
                        TreeNode treeNode = (TreeNode) node;  
                        returnValue = treeNode.isLeaf();  
                    }  
                }  
            }  
            return returnValue;  
        }  

        public Object getCellEditorValue() {  
            return textField.getText();  
        }  

        // Press enter key to save the edited value.   
        public void actionPerformed(ActionEvent e) {
            String oldName = getNameFluentTree();
            super.stopCellEditing();
            setNameModified(oldName);
        }  
    }

	public void setListGUIDiagrams(LinkedList<GUIDiagram> newListGUIDiagrams) {
		this.listGUIDiagrams = newListGUIDiagrams;		
	}

	public void repaintDiagrams() {
		for(int i = 0;i<this.listGUIDiagrams.size();i++){
			this.listGUIDiagrams.get(i).repaint();
		}
	}

	public void setTrace(Object[] traceStateList) {
		this.traceStateList = traceStateList;
	}
	
	public Object[] getTrace() {
		return this.traceStateList;
	} 
}